'''
    供应商信息页面对象
'''
import allure
from pom_ui_frame.base_page.basepage import BasePage
from selenium import webdriver


class VendorPage(BasePage):
    # 页面url
    url = 'http://39.101.122.147:3000/system/vendor'

    # 页面核心元素：与操作流程相关联的元素，其余元素不需要。
    vendor_add = ('xpath', '//div[@class="table-operator"]/button[1]')  # 元素核心内容包括定位方法以及对应的value
    supplier_name = ('id', 'supplier')
    supplier_telephone = ('id', 'telephone')
    supplier_save = ('xpath', '//div[@class="ant-modal-footer"]/div[1]/button[2]')
    supplier_assert=('xpath', '//*[@id="rcDialogTitle0"]')

    search_name = ('xpath', '//input[@placeholder="请输入名称查询"]')
    search_button = ('xpath', '//span[text()="查 询"]/..')

    # 页面的子流程封装
    def test_add_supplier(self, name, tele):
        try:
            with allure.step('1. 进入新增客户页面'):
                self.open(self.url)
            with allure.step('2. 添加客户'):
                self.click(*self.vendor_add)
                self.input(*self.supplier_name, txt=name)
                self.input(*self.supplier_telephone, txt=tele)
                self.click(*self.supplier_save)

            with allure.step('3. 强制等待'):
                self.assert_text('新增',*self.supplier_assert)
                self.wait(1)

        except:
            # 如果出现异常，则调用截图放在测试报告之中
            allure.attach(self.driver.get_screenshot_as_png(), '错误截图', allure.attachment_type.PNG)
            raise

    def test_search(self, name):
        self.open(self.url)
        self.input(*self.search_name, txt=name)
        self.click(*self.search_button)
# if __name__ == '__main__':
#     service = Service('../chromedriver.exe')
#     driver =webdriver.Chrome(service=service,options=options())
#     lp = LoginPage(driver)
#     lp.login('jsh', '123456')
#     vp = VendorPage(driver)
#     data=read('../test/test_yaml/add.yaml')
#     vp.add_supplier(data[0]['name'], data[0]['tele'])